<?php
error_reporting(0);
$senha = '';
if($_POST["btn_crip"] == "Criptografar"){
    $senha = $_POST["senha"];
}

if($_POST["btn_gerar"] == "Gerar"){
    $s = '';
    
    $qnt = $_POST["quant"];
    echo $nivel;
    while(strlen($s) < $qnt){
        if($_POST["cnum"] == 1 && strlen($s) < $qnt){
            $s .= rand(0,9);
        }
        if($_POST["cmin"] == 1 && strlen($s) < $qnt){
            $s .= chr(rand(97,122));
        }
        if($_POST["cmai"] == 1 && strlen($s) < $qnt){
            $s .= chr(rand(65,90));
        }
    }
    
    $senha = $s;
}
?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Gerador de Senhas</title>
</head>
<body>
    <h2>Gerar senha</h2>
    <form action="" method="post">
        <input type="checkbox" name="cnum" id="cnum" value="1" checked>
        <label for="cnum">Conter números</label><br>
        <input type="checkbox" name="cmin" id="cmin" value="1">
        <label for="cmin">Conter letras minúsculas</label><br>
        <input type="checkbox" name="cmai" id="cmai" value="1">
        <label for="cmai">Conter letras maiúsculas</label><br>
        Quantidade de caracteres: <input type="number" value="6" name="quant" size="2"><br>
        <input type="submit" name="btn_gerar" value="Gerar">
    </form>
    <br>
    <form action="" method="post">
        Senha: <input type="text" value="<?=$senha?>" name="senha">
        <input type="submit" name="btn_crip" value="Criptografar">
    </form>
    <h2>Criptografias</h2>
    <label>md5: </label><?=md5($senha)?><br><br>
    <label>sha1: </label><?=sha1($senha)?><br><br>
</body>
</html>
